<template>
	<view class="box">
		<view class="bgc"></view>
		<view class="textipt">
			<view class="title">
				投诉与意见
			</view>
			<u--textarea v-model="textareaVal" border="none" height="250rpx" placeholder="请填写10个字以上的描述以便我们提供更好的帮助"
				:maxlength="140" count></u--textarea>
		</view>

		<view class="img-box">
			<u-text :text="`上传图片（${fileList.length}/3）`" size="30rpx"></u-text>
			<view class="imgs">
				<u-upload :fileList="fileList" uploadIcon="plus" width="187rpx" height="187rpx" @afterRead="afterRead($event)"
					@delete="deletePic($event)" name="1" multiple :maxCount="3"></u-upload>
			</view>
		</view>

		<view class="btn" @click="submit">
			提 交
		</view>
	</view>
</template>

<script>
	import {
		UserApi
	} from '@/api';
	export default {
		data() {
			return {
				textareaVal: '',
				fileList: [],
			};
		},
		methods: {
			async afterRead(e) {
				try {
					const res = await this.$uploadFile(e.file[0], false)
					this.fileList.push({
						url: res.result.showUrl
					})
				} catch (err) {
					//TODO handle the exception
					console.log(err, 'err');
				}

			},
			deletePic(e) {
				this.fileList.splice(e.index, 1)
			},
			async submit() {
				try {
					if (!this.textareaVal) return this.$showToast('请填写信息')
					let imgs = this.fileList.map(item => item.url)
					const res = await UserApi.FeedbacksSubmit({
						message: this.textareaVal,
						title: this.textareaVal,
						imgs: imgs.join(',')
					})
					this.$showToast(res.msg)
					this.textareaVal = null
					this.fileList = []
				} catch (e) {
					//TODO handle the exception
					console.log(e);
				}
			}

		}
	}
</script>

<style lang="scss" scoped>
	.box {
		width: 100vw;
		box-sizing: border-box;
		padding: 30rpx;

		.btn {
			position: fixed;
			bottom: calc(30rpx + constant(safe-area-inset-bottom));
			bottom: calc(30rpx + env(safe-area-inset-bottom));
			left: 30rpx;
			width: 690rpx;
			height: 88rpx;
			border-radius: 50rpx;
			opacity: 1;
			background: linear-gradient(173.2deg, #f8b280 0%, #ff8b38 100%);
			text-align: center;
			line-height: 88rpx;
			color: #fff;
			font-size: 30rpx;
		}

		.img-box {
			width: 690rpx;
			height: 372rpx;
			border-radius: 12rpx;
			box-sizing: border-box;
			padding: 30rpx;
			opacity: 1;
			background: #ffffff;

			.imgs {
				display: flex;
				align-items: center;
				justify-content: space-between;
				width: 100%;
				box-sizing: border-box;
				margin-top: 68rpx;

				.img {
					width: 187rpx;
					height: 187rpx;
				}
			}
		}

		.textipt {
			width: 690rpx;
			// margin: 30rpx 0;
			// height: 367rpx;
			border-radius: 12rpx;
			padding: 35rpx;
			box-sizing: border-box;
			background: #ffffff;

			.title {
				font-size: 30rpx;
				font-weight: 400;
			}
		}

		.bgc {
			position: absolute;
			top: 0;
			left: 0;
			height: 100rpx;
			width: 100vw;
			background-color: #fef2e6;
			z-index: -1;
		}
	}
</style>